
# 首先声明最先生成的目标
build :

obj-y :=
subdir-y :=
lib_static :=
lib_dynamic :=

# 包含目标目录Makefile
#	
include Makefile


SRC_PATH = $(shell pwd)/ 

# 获取子模块的所有子目录
DIRS = $(shell find $(SRC_PATH) -maxdepth 4 -type d)  

# 
# 获取相对路径的
#
SRCS_CPP += $(foreach dir, $(DIRS), $(wildcard $(dir)/*.cpp))  
SRCS_CC += $(foreach dir, $(DIRS), $(wildcard $(dir)/*.cc))  
SRCS_C += $(foreach dir, $(DIRS), $(wildcard $(dir)/*.c))  
$(warning SRCS_CPP $(SRCS_CPP))
$(warning SRCS_CC $(SRCS_CC))
$(warning SRCS_C $(SRCS_C))

OBJS_CPP = $(subst $(TOPDIR),  $(OUTDIR), $(patsubst %.cpp, %.o, $(SRCS_CPP)))  
OBJS_CC = $(subst $(TOPDIR),  $(OUTDIR), $(patsubst %.cc, %.o, $(SRCS_CC)))
OBJS_C = $(subst $(TOPDIR),  $(OUTDIR), $(patsubst %.c, %.o, $(SRCS_C)))
$(warning OBJS_CPP $(OBJS_CPP))
$(warning OBJS_CC $(OBJS_CC))
$(warning OBJS_C $(OBJS_C))

# 去掉 TOPDIR
SRC_RELATIVE_PATH = $(subst $(TOPDIR), , $(SRC_PATH))
# 替换 TOPDIR 为 OUTDIR
OBJ_PATH  = $(subst $(TOPDIR),  $(OUTDIR), $(SRC_PATH))
# 去掉 TOPDIR
OBJ_RELATIVE_PATH = $(subst $(TOPDIR), , $(OBJ_PATH))



# 包含编译相关配置
include $(TOPDIR)/mk/config.mk
include $(TOPDIR)/mk/common.mk
include $(TOPDIR)/mk/library.mk

# 包含子目录的头文件
CFLAGS  += $(addprefix -I, $(DIRS))




# 虚假目标: 必须是 include 下面
.PHONY : build $(lib_static) $(lib_dynamic) $(program)

# 编译
build : $(OBJS_CPP) $(OBJS_CC) $(OBJS_C) $(lib_static) $(lib_dynamic) $(program) 



